<?php
/* @var $this ArticleController */
/* @var $model Article */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'article-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>
	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'caption'); ?>
		<?php echo $form->textField($model,'caption',array('size'=>60,'maxlength'=>256)); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'detail_text'); ?>
		<?php echo $form->textArea($model,'detail_text',array('rows'=>6, 'cols'=>50)); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'anons_text'); ?>
		<?php echo $form->textField($model,'anons_text',array('size'=>60,'maxlength'=>512)); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'date_create'); ?>
		<?php echo $form->textField($model,'date_create'); ?>
	</div>
	
	<div class="row">
		<?php echo $form->labelEx($model, 'image');?>
		<?php echo $form->fileField($model, 'image'); ?>
	</div>

	<?php if (!$model->isNewRecord) { ?>
	<?php $images = new CActiveDataProvider('ArticlePhotos', array(
	  'criteria' => array(
	    'condition' => 'article_id=' . $model->id,
	  ),
	  'pagination' => array(
	    'pageSize' => 20,
	  ),
	));
	 
	$this->widget('zii.widgets.grid.CGridView', array(
	  'id' => 'image-grid',
	  'dataProvider' => $images,
	  'template' => "{items}",
	  'columns' => array(
	    array(
	      'header' => 'Изображение',
	      'type' => 'raw',
	      'value' => function ($data) {
	        return CHtml::image(Article::getFolder($data->path).$data->path, $data->caption, array('style' => 'height: 100px;'));
	      }
	    ),
	    array(
	      'header' => 'Название',
	      'filter' => false,
	      'value' => function ($data) {
	        return $data->caption;
	      }
	    ),
	    array(
	      'class' => 'CButtonColumn',
	      'template' => '{delete}',
	      'deleteButtonUrl' => 'Yii::app()->createUrl("/article/deleteImage", array("id" => $data->id))',
	    ),
	  ),
	));?>
	<?php } ?>
	
	<div class="row buttons">
		<?php echo CHtml::submitButton('Сохранить'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->